package org.ufinity.hsms.module;


import org.ufinity.hsms.R;
import org.ufinity.hsms.common.utils.PageParameter;
import org.ufinity.hsms.common.utils.TabTag;
import org.ufinity.hsms.module.alarm.AlarmStackActivity;
import org.ufinity.hsms.module.busy.BusyStackActivity;
import org.ufinity.hsms.module.device.DeviceStackActivity;
import org.ufinity.hsms.module.home.HomeStackActivity;
import org.ufinity.hsms.module.panel.PanelStackActivity;
import org.ufinity.hsms.module.setting.SettingStackActivity;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;

public class TabbarActivity extends TabActivity{
	public static RadioGroup group;
	public static TabHost tabHost;
	private Intent intentHome;
	private Intent intentPanel;
	private Intent intentAlarm;
	private Intent intentBusy;
	private Intent intentDevice;
	private Intent intentSettings;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		// 取消标题栏
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		
		
		setContentView(R.layout.maintab);
		group = (RadioGroup)findViewById(R.id.main_radio);
		tabHost = getTabHost();
		intentHome = new Intent(this,HomeStackActivity.class);
		intentPanel = new Intent(this,PanelStackActivity.class);
		intentAlarm = new Intent(this,AlarmStackActivity.class);
		intentDevice = new Intent(this,DeviceStackActivity.class);
		intentBusy = new Intent(this,BusyStackActivity.class);
		intentSettings = new Intent(this,SettingStackActivity.class);
		
		tabHost.addTab(tabHost.newTabSpec(TabTag.TAB_HOME)
	                .setIndicator(TabTag.TAB_HOME)
	                .setContent(intentHome));
		tabHost.addTab(tabHost.newTabSpec(TabTag.TAB_PANNEL)
                .setIndicator(TabTag.TAB_PANNEL)
                .setContent(intentPanel));
	    tabHost.addTab(tabHost.newTabSpec(TabTag.TAB_ALARM)
	                .setIndicator(TabTag.TAB_ALARM)
	                .setContent(intentAlarm));
	    tabHost.addTab(tabHost.newTabSpec(TabTag.TAB_DEVICE)
	    		.setIndicator(TabTag.TAB_DEVICE)
	    		.setContent(intentDevice));
	    tabHost.addTab(tabHost.newTabSpec(TabTag.TAB_BUSY)
	    		.setIndicator(TabTag.TAB_BUSY)
	    		.setContent(intentBusy));
	    tabHost.addTab(tabHost.newTabSpec(TabTag.TAB_SETTINGS)
	    		.setIndicator(TabTag.TAB_SETTINGS)
	    		.setContent(intentSettings));
	    group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				PageParameter.bTab = true;
				switch (checkedId) {
				case R.id.tab_home:
					tabHost.setCurrentTabByTag(TabTag.TAB_HOME);
					break;
				case R.id.tab_pannel:
					tabHost.setCurrentTabByTag(TabTag.TAB_PANNEL);
					break;
				case R.id.tab_alarm:
					tabHost.setCurrentTabByTag(TabTag.TAB_ALARM);
					break;
				case R.id.tab_device:
					tabHost.setCurrentTabByTag(TabTag.TAB_DEVICE);
					break;
				case R.id.tab_busy:
					tabHost.setCurrentTabByTag(TabTag.TAB_BUSY);
					break;
				case R.id.tab_settings:
					tabHost.setCurrentTabByTag(TabTag.TAB_SETTINGS);
					break;

				default:
					break;
				}
			}
		});
	    //初始化光标在第一个
	    group.check(R.id.tab_home);
	}
}
